package LeetCode.leetcode;

/**
 * 缺失数字
 * @author: leiwenkang02@meituan.com
 * @date: 2018/8/27
 * @time: 20:58
 */
public class Test268缺失数字 {
    public static void main(String[] args) {
        int[] nums = {3, 0, 1};
        System.out.println(missingNumber(nums));
    }
    public static int missingNumber(int[] nums) {
        int expectedSum = 0;
        int actualSum = 0;
        for (int i = 1; i <= nums.length; i++) {
            expectedSum += i;
            actualSum += nums[i - 1];
        }

        return expectedSum - actualSum;
    }
}
